<?php
if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');
global $_GPC,$_W;
$pro_id= intval($_GPC['pro_id']);
$uniacid = $_W['uniacid'];
if(empty($pro_id)){
    message('抱歉，传递的参数错误！','', 'error');              
}

$lists = pdo_fetchall("SELECT * FROM " . tablename("tim_welfare_fund") . " WHERE pro_id =:pro_id AND fund_true=:fund_true  ORDER BY fund_time DESC ", array(":pro_id"=>$pro_id, ":fund_true"=>true));
$set =  pdo_fetch("SELECT * FROM ".tablename('tim_welfare_set')." WHERE uniacid=:uniacid",array(':uniacid'=>$uniacid));
$list = array();
		foreach ($lists as $k) {
			$mem_name = pdo_fetch("SELECT *  FROM ".tablename('tim_welfare_member')."WHERE mem_id = :mem_id", array(':mem_id' => $k['mem_id']));
			$pro_name = pdo_fetch("SELECT pro_name  FROM ".tablename('tim_welfare_project')."WHERE pro_id = :pro_id", array(':pro_id' => $k['pro_id']));
			$rows = array( 
				'fund_id'    => $k['fund_id'],
				'pro_name'  => $pro_name['pro_name'],
				'mem_photo'  => $mem_name['mem_photo'],
				'mem_name'   => $mem_name['mem_name'],
				'order_num'  => $k['order_num'],
				'fund_value' => $k['fund_value'],
				'fund_time' => $k['fund_time']
			);
			array_push($list, $rows);
		}

$tableheader = array("昵称", "订单号", "项目名称", "支持金额", "支持时间");


$html = "\xEF\xBB\xBF";
foreach ($tableheader as $value) {
	$html .= $value . "\t ";
}
$html .= "\n";
foreach ($list as $value) {
	$html .= $value['mem_name'] . "\t ";
	$html .= $value['order_num']  . "\t ";
	$html .= $value['pro_name']  . "\t ";

    $html .= $value['fund_value'] . "\t ";

	$html .= ($value['fund_time'] == 0 ? '' : date('Y-m-d H:i',$value['fund_time'])) . "\n";

}


header("Content-type:text/csv");
header("Content-Disposition:attachment; filename=捐款用户数据.xls");

echo $html;
exit();
